package com.jungle.sp.daily.controller;

import com.fasterxml.jackson.annotation.JsonView;
import com.jungle.sp.daily.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

/**
 * 对于依赖视图的控制器，只需将序列化视图类添加到model中即可
 * 依赖视图的用全局注解不生效
 */
@Controller
public class UserViewController {
    @GetMapping("/userview")
    public ModelAndView userView(Model model) {
        User user = new User(1L, "pack", "四川乌鲁木齐市", "123456",
                "152528202504096514", "pack@qq.com");
        model.addAttribute("user", user);
        model.addAttribute(JsonView.class.getName(), User.PublicView.class);
        return new ModelAndView(new MappingJackson2JsonView());
    }
}